<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true">
      <el-form-item label="试卷类别名称" prop="concreteName">
        <el-input
          v-model="queryParams.concreteName"
          placeholder="请输入试卷类别"
          clearable
          size="small"
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>


      <el-form-item>
        
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <!-- <router-link :to="{path:'/category/paper/edit'}" class="link-left">
          <el-button size="mini" type="primary" icon="el-icon-plus" >添加</el-button>
        </router-link> -->
      </el-form-item>
    </el-form>


    <el-table v-loading="loading" :data="roleList">
     
      <el-table-column prop="id" label="序号" width="100px"/>
      <el-table-column prop="concreteName" label="试卷类别名称" />
      <el-table-column prop="createTime" label="创建时间" />
        <el-table-column label="状态" align="center" width="100">
        <template slot-scope="scope">
          <el-switch
            v-model="scope.row.isEnabled"
            :active-value="1"
            :inactive-value="0"
            @change="handleStatusChange(scope.row)"
          ></el-switch>
        </template>
      </el-table-column>
      <!-- <el-table-column width="360px" label="操作" align="center">
        <template slot-scope="{row}">
          
          <router-link :to="{path:'/category/lecturetitle/edit', query:{id:row.id,titleName:row.titleName}}" class="link-left">
            <el-button size="mini" >编辑</el-button>
          </router-link>
          <el-button  size="mini" type="danger" @click="handleDelete(row)" class="link-left">删除</el-button>
        </template>
      </el-table-column> -->
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParam.pageNum"
      :limit.sync="queryParam.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改角色配置对话框 -->

    <!-- 分配角色数据权限对话框 -->
 
  </div>
</template>

<script>
import { allCategory,selectCategory,getCategoryPageList,createCategory,deleteCategory,changeStatus} from "@/api/category/category";

export default {
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 角色表格数据
      roleList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 是否显示弹出层（数据权限）
      openDataScope: false,
      // 日期范围
      dateRange: [],
      // 状态数据字典
      statusOptions: [],
      // 数据范围选项
    
      // 菜单列表
      menuOptions: [],
      // 部门列表
      deptOptions: [],
      // 查询参数
      queryParams: {
        pageIndex: 1,
        pageSize: 10,
        categoryId: 2,
        concreteName: "",
        role: 1,
      },
      queryParam: {
        pageNum: 1,    
        pageSize: 10 
      },
      
      // 表单参数
      form: {},
      defaultProps: {
        children: "children",
        label: "label"
      },
      // 表单校验
      rules: {
        roleName: [
          { required: true, message: "角色名称不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
    
  },
  methods: {
    /** 查询角色列表 */
    getList() {
      this.loading = true;
      getCategoryPageList(this.queryParams).then(
        response => {
         // console.log(response.response.list)
          this.roleList = response.response.list;
          this.total = response.response.total;
          this.loading = false;
        }
      );
    },
    // 角色状态修改
    handleStatusChange(row) {
      console.log(row.isEnabled)
      let text = row.isEnabled === 0? "停用" : "启用";
      console.log(text)
      this.$confirm('确认要"' + text + '""' + row.concreteName + '"吗?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return changeStatus(row.id);
        }).then(() => {
          this.msgSuccess(text + "成功");
        }).catch(function() {
          row.isEnabled = row.isEnabled === 1 ? 0 : 1;
        });
    },
    
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
   
    /** 删除按钮操作 */
    handleDelete(row) {   
      console.log(row.id)
      deleteCategory(row.id).then(re => {
        if (re.code === 1) {
         this.getList();
          this.$message.success(re.message)
        } else {
          this.$message.error(re.message)
        }
      })
    }
  }
};
</script>